﻿@{
    Layout = null;
}

<div>
    <div class="input-group">
        <div class="col-3 pr-0" style="display: none">
            <label id="Preparation-ReagentsId">@ViewData["ReagentsId"]</label>
        </div>
        <div class="input-group">
            <div class="col-3 pr-0">
                <span class="input-group-text font-rfs border-radius-noright noRightBorder">名称</span>
            </div>
            <div class="col-9 pl-0">
                <span id="Preparation-Name" class="form-control font-rfs border-radius-noleft"></span>
            </div>
        </div>
        <div class="input-group">
            <div class="col-3 pr-0">
                <span class="input-group-text font-rfs border-radius-noright noRightBorder">配制浓度*</span>
            </div>
            <div class="col-9 pl-0">
                <input id="Preparation-Concentration" class="form-control font-rfs border-radius-noleft" />
            </div>
        </div>
        <div id="Preparation-MaterialEmbed" class="input-group"></div>
        <div class="input-group">
            <div class="col-3 pr-0">
                <span class="input-group-text font-rfs border-radius-noright noRightBorder">配制数量*</span>
            </div>
            <div class="col-9 pl-0 input-group">
                <input id="Preparation-PreparationQuantity" class="form-control font-rfs border-radius-noleft" style="width:45%" placeholder="有效数字" />
                <input id="Preparation-QuantityUnit" class="form-control font-rfs border-radius-noleft" style="width:55%" />
            </div>
        </div>
        <div class="input-group">
            <div class="col-3 pr-0">
                <span class="input-group-text font-rfs border-radius-noright noRightBorder">温度</span>
            </div>
            <div class="col-9 pl-0 input-group">
                <input id="Preparation-Temperature" class="form-control font-rfs border-radius-noleft" style="width:45%" placeholder="选填，有效数字" />
                <select id="Preparation-TemperatureUnit" class="form-control font-rfs border-radius-noleft" style="width:55%"></select>
            </div>
        </div>
        <div class="input-group">
            <div class="col-3 pr-0">
                <span class="input-group-text font-rfs border-radius-noright noRightBorder">湿度</span>
            </div>
            <div class="col-9 pl-0 input-group">
                <input id="Preparation-Humidity" class="form-control font-rfs border-radius-noleft" style="width:45%" placeholder="选填，有效数字" />
                <select id="Preparation-HumidityUnit" class="form-control font-rfs border-radius-noleft" style="width:55%"></select>
            </div>
        </div>
    </div>
    <div class="text-right">
        <button id="Preparation-confirm" class="btn btn-primary font-rfs">确定</button>
        <button id="Preparation-cancel" type="button" class="btn btn-info font-rfs" data-dismiss="modal">取消</button>
    </div>
</div>

<script>

    $(document).ready(function () {
        LoadReagent();
        LoadUnitByType('Preparation-TemperatureUnit', "温度单位");
        LoadUnitByType('Preparation-HumidityUnit', "湿度单位");
    });

    function LoadReagent() {
        $.post("\\Reagent\\GetReagentById", {
            Id: $("#Preparation-ReagentsId").html()
        }, function (data) {
            $("#Preparation-Name").text(data.name);
            $("#Preparation-Concentration").val(data.concentration);
            $("#Preparation-PreparationQuantity").val(data.preparationQuantity);
            $("#Preparation-QuantityUnit").val(data.quantityUnit);
        });
    }

    $("#Preparation-confirm").click(function () {
        if ($.trim($("#Preparation-Concentration").val()).length == 0) {
            alert("浓度不能为空！");
            $("#Preparation-Concentration").addClass('error-style');
            return false;
        }
        if ($.trim($("#Preparation-PreparationQuantity").val()).length == 0) {
            alert("配制数量不能为空！");
            $("#Preparation-PreparationQuantity").addClass('error-style');
            return false;
        }
        if ($.trim($("#Preparation-QuantityUnit").val()).length == 0) {
            alert("数量单位不能为空！");
            $("#Preparation-QuantityUnit").addClass('error-style');
            return false;
        }
        if ($.trim($("#Preparation-Temperature").val()).length > 0) {
            if ($("#Preparation-TemperatureUnit").find("option:selected").text().length == 0) {
                alert("温度单位不能为空！");
                $("#Preparation-TemperatureUnit").addClass('error-style');
                return false;
            }
        }
        if ($.trim($("#Preparation-Humidity").val()).length > 0) {
            if ($("#Preparation-HumidityUnit").find("option:selected").text().length == 0) {
                alert("湿度单位不能为空！");
                $("#Preparation-HumidityUnit").addClass('error-style');
                return false;
            }
        }

        var jsonStr = {};
        jsonStr["ReagentId"] = $("#Preparation-ReagentsId").html();
        jsonStr["Name"] = $.trim($("#Preparation-Name").text());
        jsonStr["Concentration"] = $.trim($("#Preparation-Concentration").val());
        jsonStr["PreparationQuantity"] = $.trim($("#Preparation-PreparationQuantity").val());
        jsonStr["QuantityUnit"] = $.trim($("#Preparation-QuantityUnit").val());

        if ($.trim($("#Preparation-Temperature").val()).length > 0) {
            jsonStr["Temperature"] = $.trim($("#Preparation-Temperature").val());
            jsonStr["TemperatureUnit"] = $("#Preparation-TemperatureUnit").find("option:selected").text();
        }
        if ($.trim($("#Preparation-Humidity").val()).length > 0) {
            jsonStr["Humidity"] = $.trim($("#Preparation-Humidity").val());
            jsonStr["HumidityUnit"] = $("#Preparation-HumidityUnit").find("option:selected").text();
        }

        $.post("postAddRecord", {
            jsonStr: JSON.stringify(jsonStr)
        }, function (data) {
            alert(data);
            $("#Preparation-cancel").click();
        });

    });
    
    $("#Preparation-cancel").click(function () {
        var modalID = $("#Preparation-Parent-ModalID").html();
        $("#" + modalID).modal('hide');
    });

</script>
